package com.smart.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.smart.common.dao.AbstractDao;
import com.smart.domain.Menu;
import com.smart.tools.ObjectHelper;

/**
 * 
 * 版权所有：xxxxxxx
 * @Description: 菜单
 * @Title: MenuDao.java 
 * @ClassName: MenuDao 
 * @author tangyan 
 * @date 2019年2月13日 下午6:27:50 
 * @version V1.0
 */
@Repository
@Transactional
public class MenuDao extends AbstractDao<Menu>{

	
	/**
	 * 
	 * @Title: queryMenuAuthority 
	 * @Description: 查询菜单权限
	 * @author tangyan 
	 * @param conditions
	 * @return
	 */
	public List<Menu> queryMenu(Map<String, Object> conditions){
		StringBuffer hql = new 	StringBuffer(" from Menu m  where m.isDeleted = 0 ");
		if(ObjectHelper.isNotEmpty(conditions.get("title"))){
			hql.append(" and m.title = :title ");
		}
		if(ObjectHelper.isNotEmpty(conditions.get("menuCode"))){
			hql.append(" and m.menuCode = :menuCode ");
		}
		if(ObjectHelper.isNotEmpty(conditions.get("parentId"))){
			hql.append(" and m.parentId = :parentId ");
		}
		if(ObjectHelper.isNotEmpty(conditions.get("level"))){
			hql.append(" and m.level = :level ");
		}
		
		return this.findByHql(hql.toString(), conditions);
	}
	
	
	/**
	 * 
	 * @Title: queryMenuAuthority 
	 * @Description: 根据权限查询菜单
	 * @author tangyan 
	 * @param conditions
	 * @return
	 */
	public List<Menu> queryMenuAuthority(Map<String, Object> conditions){
		StringBuffer hql = new 	StringBuffer(" from MenuAuthority ma , Menu m  where m.id = ma.menuId and ma.isDeleted = 0 and  m.isDeleted = 0 ");
		if(ObjectHelper.isNotEmpty(conditions.get("title"))){
			hql.append(" and m.title = :title ");
		}
		if(ObjectHelper.isNotEmpty(conditions.get("menuCode"))){
			hql.append(" and m.menuCode = :menuCode ");
		}
		if(ObjectHelper.isNotEmpty(conditions.get("roleIdIn"))){
			hql.append(" and m.parentId in :roleIdIn ");
		}
		if(ObjectHelper.isNotEmpty(conditions.get("parentId"))){
			hql.append(" and m.parentId = :parentId ");
		}
		
		
		return this.findByHql(hql.toString(), conditions);
	}
}
